
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 17/11/2013 20:29:50
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class Order
    /// </summary>
    [Serializable]
    public partial class Order : _DomainLayer_Base  
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual int Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_DeliveryMode.
        /// </summary>
        /// <value>The FK_DeliveryMode.</value>
        /// <remarks>
        /// Foregn key of Order
        /// 
        /// </remarks>
        public virtual int FK_DeliveryMode
        {
            get { return _fK_DeliveryMode; }
            set
            {
                if (_fK_DeliveryMode != value)
                {
                    if (DeliveryMode != null && DeliveryMode.Id != value)
                    {
                        DeliveryMode = null;
                    }
                    _fK_DeliveryMode = value;
                }
            }
        }
        private int _fK_DeliveryMode;
    	
        /// <summary>
        /// Gets or sets FK_Contact.
        /// </summary>
        /// <value>The FK_Contact.</value>
        /// <remarks>
        /// Foregn key of Order
        /// 
        /// </remarks>
        public virtual int FK_Contact
        {
            get { return _fK_Contact; }
            set
            {
                if (_fK_Contact != value)
                {
                    if (Contact != null && Contact.Id != value)
                    {
                        Contact = null;
                    }
                    _fK_Contact = value;
                }
            }
        }
        private int _fK_Contact;
    	
        /// <summary>
        /// Gets or sets DeliveryAddress.
        /// </summary>
        /// <value>The DeliveryAddress.</value>
        public virtual string DeliveryAddress
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets InvoiceAddress.
        /// </summary>
        /// <value>The InvoiceAddress.</value>
        public virtual string InvoiceAddress
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets OrderRef.
        /// </summary>
        /// <value>The OrderRef.</value>
        public virtual string OrderRef
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets OrderDate.
        /// </summary>
        /// <value>The OrderDate.</value>
        public virtual System.DateTime OrderDate
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets PackageCount.
        /// </summary>
        /// <value>The PackageCount.</value>
        public virtual int PackageCount
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets ExclusiveOfTaxeTotal.
        /// </summary>
        /// <value>The ExclusiveOfTaxeTotal.</value>
        public virtual decimal ExclusiveOfTaxeTotal
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets VATAmount.
        /// </summary>
        /// <value>The VATAmount.</value>
        public virtual decimal VATAmount
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets AllTaxeInclusiveTotal.
        /// </summary>
        /// <value>The AllTaxeInclusiveTotal.</value>
        public virtual decimal AllTaxeInclusiveTotal
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets IsDraft.
        /// </summary>
        /// <value>The IsDraft.</value>
        public virtual int IsDraft
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion

        #region Navigation Properties
        public virtual Contact Contact
        {
            get { return _contact; }
            set
            {
                if (!ReferenceEquals(_contact, value))
                {
                    var previousValue = _contact;
                    _contact = value;
                    FixupContact(previousValue);
                }
            }
        }
        private Contact _contact;
        public virtual DeliveryMode DeliveryMode
        {
            get { return _deliveryMode; }
            set
            {
                if (!ReferenceEquals(_deliveryMode, value))
                {
                    var previousValue = _deliveryMode;
                    _deliveryMode = value;
                    FixupDeliveryMode(previousValue);
                }
            }
        }
        private DeliveryMode _deliveryMode;
    
        /// <summary>
        /// Link Order to all OrderDetail
        /// </summary>
        public virtual ICollection<OrderDetail> OrderDetail
        {
            get
            {
                if (_orderDetail == null)
                {
                    var newCollection = new FixupCollection<OrderDetail>();
                    newCollection.CollectionChanged += FixupOrderDetail;
                    _orderDetail = newCollection;
                }
                return _orderDetail;
            }
            set
            {
                if (!ReferenceEquals(_orderDetail, value))
                {
                    var previousValue = _orderDetail as FixupCollection<OrderDetail>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupOrderDetail;
                    }
                    _orderDetail = value;
                    var newValue = value as FixupCollection<OrderDetail>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupOrderDetail;
                    }
                }
            }
        }
        private ICollection<OrderDetail> _orderDetail;

        #endregion

        #region Association Fixup
    
        private void FixupContact(Contact previousValue)
        {
            if (previousValue != null && previousValue.Order.Contains(this))
            {
                previousValue.Order.Remove(this);
            }
    
            if (Contact != null)
            {
                if (!Contact.Order.Contains(this))
                {
                    Contact.Order.Add(this);
                }
                if (FK_Contact != Contact.Id)
                {
                    FK_Contact = Contact.Id;
                }
            }
        }
    
        private void FixupDeliveryMode(DeliveryMode previousValue)
        {
            if (previousValue != null && previousValue.Order.Contains(this))
            {
                previousValue.Order.Remove(this);
            }
    
            if (DeliveryMode != null)
            {
                if (!DeliveryMode.Order.Contains(this))
                {
                    DeliveryMode.Order.Add(this);
                }
                if (FK_DeliveryMode != DeliveryMode.Id)
                {
                    FK_DeliveryMode = DeliveryMode.Id;
                }
            }
        }
    
        private void FixupOrderDetail(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (OrderDetail item in e.NewItems)
                {
                    item.Order = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (OrderDetail item in e.OldItems)
                {
                    if (ReferenceEquals(item.Order, this))
                    {
                        item.Order = null;
                    }
                }
            }
        }

        #endregion

    }
}
